import * as actionTypes from './actionTypes';

const defaultState = {
	scoreData: [],
	collectData: [],
	selectFlag: false
};

export default (state = defaultState, action) => {
	const newState = JSON.parse(JSON.stringify(state)) 
	switch(action.type) {
		case actionTypes.Get_Music_Score:
			newState.scoreData = action.data
			return newState;
		case actionTypes.Get_Score_Collect:
			newState.collectData = action.data
			return newState;
		case actionTypes.Change_Select_Flag:
			newState.selectFlag = action.data
			return newState;
		case actionTypes.Add_Score_Collect:
			if (newState.scoreData[action.data]) {
				newState.scoreData[action.data].FAVORITE_ID = '10086'
			}
			console.log(newState, '...newState')
			return newState;
		case actionTypes.Sub_Score_Collect:
			// 1 -- 曲谱库  2 -- 收藏曲谱
			if (action.mold === 1) {
				if (newState.scoreData[action.data]) {
					newState.scoreData[action.data].FAVORITE_ID = ''
				}
			}
			if (action.mold === 2) {
				if (newState.collectData[action.data]) {
					newState.collectData.splice(action.data, 1)
				}
			}
			return newState;	
		default:
			return state;
	}
}